package com.kun.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kun.dto.SysTenantPackageDTO;
import com.kun.entity.SysTenantPackage;
import com.kun.service.SysTenantPackageService;
import com.kun.util.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author kun.li
 */
@RestController
@RequestMapping("tenantPackage")
@RequiredArgsConstructor
@Tag(name = "租户套餐管理")
public class SysTenantPackageController {

    private final SysTenantPackageService sysTenantPackageService;

    @PostMapping("page")
    @Operation(summary = "分页租户套餐")
    public ResponseResult<Page<SysTenantPackage>> pageTenant(@RequestBody SysTenantPackageDTO sysTenantPackageDTO) {
        Page<SysTenantPackage> sysTenantPage = sysTenantPackageService.page(Page.of(sysTenantPackageDTO.getPage(), sysTenantPackageDTO.getSize()));
        return ResponseResult.success(sysTenantPage);
    }

    @PostMapping("save")
    @Operation(summary = "保存租户套餐")
    public ResponseResult<Boolean> save(@RequestBody SysTenantPackage sysTenantPackage) {
        return ResponseResult.success(sysTenantPackageService.save(sysTenantPackage));
    }

    @PostMapping("update")
    @Operation(summary = "修改租户套餐")
    public ResponseResult<Boolean> update(@RequestBody SysTenantPackage sysTenantPackage) {
        return ResponseResult.success(sysTenantPackageService.updateById(sysTenantPackage));
    }

    @DeleteMapping("remove/{packageId}")
    @Operation(summary = "删除套餐")
    public ResponseResult<Boolean> remove(@PathVariable String packageId) {
        return ResponseResult.success(sysTenantPackageService.removeById(packageId));
    }
}
